package com.lepu.app.fun.chat.business.chatcore;

import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.xmlpull.v1.XmlPullParser;

/**
 * Created by weichaoyang on 12/09/2015.
 * 在线咨询解析
 */
public class QuestionProvider implements PacketExtensionProvider {
    @Override
    public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
        boolean done = false;
        QuestionPacketExtension received = new QuestionPacketExtension();
        while (!done) {
            int eventType = parser.next();
            String name = parser.getName();//XML Tab标签
            if (eventType == XmlPullParser.START_TAG) {
                if (name.equals("type")) {
                    received.setNodeType(parser.nextText());
                } else if (name.equals("id")) {
                    received.setQuestionID(parser.nextText());
                } else if (name.equals("content")) {
                    received.setQuestioncContent(parser.nextText());
                }
            }
            if (eventType == XmlPullParser.END_TAG) {
                if (received.getElementName().equals(name)) {
                    done = true;
                }
            }
        }
        return received;
    }

}
